'use strict';

/**
 * @ngdoc overview
 * @name sumerApp
 * @description
 * # Sumer App
 *
 * Main module of the application.
 */
angular.module('common', []);
angular.module('blog', ['ngResource', 'btford.modal']);
angular.module('comment', []);
angular.module('microblog', []);
angular.module('photo', []);
angular.module('home', []);
angular.module('personalcenter', []);
angular.module('personaldocument', []);
angular.module('friend', []);
angular.module('space', []);
angular.module('share', []);
angular.module('course', []);

angular
    .module('sumerApp', [
        'ngAnimate',
        'ngCookies',
        'ngResource',
        'ngRoute',
        'ngSanitize',
        'ngTouch',
        'ui.tinymce',
        'btford.modal',
        'flow',
        'common',
        'comment',
        'blog',
        'microblog',
        'photo',
        'home',
        'friend',
        'personalcenter',
        'personaldocument',
        'space',
        'share',
        'course',
        'angular-flexslider'
    ])

    .config(['flowFactoryProvider', function (flowFactoryProvider) {
        flowFactoryProvider.defaults = {
            target: '/drm/att/mup?token=12qwaszxcvdfer34',
            permanentErrors: [404, 500, 501],
            testChunks: false,
            fileParameterName: 'upload'
        };
        /*flowFactoryProvider.on('catchAll', function (event) {
         console.log('catchAll', arguments);
         });*/
    }])

    .controller('CommonCtrl', [
        '$rootScope',
        '$cookies',
        'CurrentUser',
        'ThirdPartyPaths',
        '$routeParams',
        function ($rootScope, $cookies, CurrentUser, ThirdPartyPaths, $routeParams) {
            CurrentUser.get(function () {
                $rootScope.currentUser = {
                    id: $cookies.userid,
                    name: $cookies.username
                };
                $rootScope.visitedUserIsSameAsCurrentUser = function () {
                    return $routeParams.userId &&
                        $rootScope.currentUser.id &&
                        $routeParams.userId === $rootScope.currentUser.id;
                };
            });

            $rootScope.thirdPartyPaths = {
                collect: '',
                medal: '',
                group: '',
                course: '',
                share: ''
            };

            ThirdPartyPaths.get(function (paths) {
                $rootScope.thirdPartyPaths = paths;
            });

            $rootScope.visitedUserId = $routeParams.userId;
        }]);
